﻿
Partial Public Class eventComb
    Public Shared Function failed() As eventComb
        Return New eventComb(Function() As Boolean
                                 Return False
                             End Function)
    End Function

    Public Shared Function succeeded() As eventComb
        Return New eventComb(Function() As Boolean
                                 Return goto_end()
                             End Function)
    End Function

    Public Shared Function [return](ByVal d As _do(Of eventComb)) As eventComb
        assert(Not d Is Nothing)
        Return do_(Function() As eventComb
                       Dim rtn As eventComb = Nothing
                       rtn = d()
                       If rtn Is Nothing Then
                           Return eventComb.succeeded()
                       Else
                           Return rtn
                       End If
                   End Function,
                   eventComb.failed())
    End Function

    Public Shared Function [return](ByVal v As void(Of eventComb)) As eventComb
        assert(Not v Is Nothing)
        Return [return](Function() As eventComb
                            Dim r As eventComb = Nothing
                            v(r)
                            Return r
                        End Function)
    End Function
End Class
